package com.ls.socketio.repository.dao;

import com.ls.socketio.bean.BuildInfo;
import com.ls.socketio.repository.BuildRepository;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author liShan
 * @date 2019/9/3 17:32
 */
@Component
public class BuildRepositoryImpl {

    @Resource
    private BuildRepository buildRepository;

    /**
     * 添加酒店栋数
     * @param buildInfo 酒店栋数
     */
    public void addBuild(BuildInfo buildInfo){
        buildRepository.save(buildInfo);
    }

    /**
     * 根据酒店id查询酒店楼栋
     * @param hotelId 酒店id
     * @return 酒店楼栋
     */
    public List<BuildInfo> findByHotelId(int hotelId){
        BuildInfo buildInfo = BuildInfo.builder().hotelId(hotelId).build();
        return buildRepository.findAll(Example.of(buildInfo), new Sort(Sort.Direction.ASC, "buildNum"));
    }

}
